package com.hgk.common.common.ui.view;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import width.hgk.wanwan.R;

/**
 * 自定义标题栏View
 * 
 * 这个类是一个带标题栏以及按钮的view 以后写东西可以直接setContentView(view)
 * 然后view.get...Laytou.addView(你新的布局)
 * 
 * @author fyh
 * 
 */
public class BallTitleView extends RelativeLayout {
	private View view;
	private Button button_left;
	private Button button_right;
	private RelativeLayout reLayout_left;
	private RelativeLayout reLayout_right;
	private TextView textView;
	private RelativeLayout relativeLayout;
	private FrameLayout framelayout;
	private RelativeLayout mRLMengCeng; /* 蒙层 */
	private LinearLayout linearlayout;
	private TextView nodata_tv1;// 无数据content1
	private TextView nodata_tv2;// 无数据content2
	private TextView noNetData_tv1;// 无网路时content2
	private TextView noNetData_tv2;// 无网路时content2
	private ImageView nodata_img;// 无数据图片

	public ImageView getNodata_img() {
		return nodata_img;
	}

	public TextView getNodata_tv1() {
		return nodata_tv1;
	}

	public TextView getNodata_tv2() {
		return nodata_tv2;
	}

	public TextView getNet_tv1() {
		return noNetData_tv1;
	}

	public TextView getNet_tv2() {
		return noNetData_tv2;
	}

	public Button getmRefreshButton() {
		return mRefreshButton;
	}
	public Button getmRefreshNoDateButton(){
		return mRefreshNoDateButton;
	}

	public void startAnim() {
		mIvAnim.postDelayed(new Runnable() {
			@Override
			public void run() {
				if (mAnim != null) {
					if (mAnim.isRunning()) {
						mAnim.stop();
					}
					mAnim.start();
				}
			}
		}, 0);
	}

	public void stopAnim() {
		if (mAnim == null)
			return;
		if (mAnim.isRunning()) {
			mAnim.stop();
		}
	}

	public LinearLayout getLoadingView() {
		return loadingView;
	}

	private RelativeLayout relativeLayout_right;
	private RelativeLayout relativeLayout_left;
	private Button mRefreshButton;
	private Button mRefreshNoDateButton;
	private LinearLayout loadingView;
	private ImageView mIvAnim;
	private AnimationDrawable mAnim;

	public AnimationDrawable getmAnim() {
		return mAnim;
	}

	private View nodataView;
	private View netView;

	public View getNodataView() {
		return nodataView;
	}

	public View getNetView() {
		return netView;
	}

    /**
     * 得到标题textview
     */
    public TextView getTitleTv(){
        return textView;
    }
	public BallTitleView(Context context) {
		super(context);
		view = LayoutInflater.from(context).inflate(R.layout.playing_title_view,
				null);
		button_left = (Button) view
				.findViewById(R.id.baby_title_view_button_left);
		reLayout_left = (RelativeLayout) view.findViewById(R.id.baby_title_view_rl_left);
		button_right = (Button) view
				.findViewById(R.id.baby_title_view_button_right);
		reLayout_right = (RelativeLayout) view.findViewById(R.id.baby_title_view_rl_right);
		textView = (TextView) view.findViewById(R.id.baby_title_view_text);
		relativeLayout = (RelativeLayout) view
				.findViewById(R.id.baby_title_view_linearlayout);
		mRLMengCeng = (RelativeLayout) view
				.findViewById(R.id.baby_title_mengceng);
		framelayout = (FrameLayout) view
				.findViewById(R.id.baby_title_view_framelayout);
		linearlayout = (LinearLayout) view
				.findViewById(R.id.baby_title_view_linearlayout_top);
		netView = (LinearLayout) view.findViewById(R.id.no_net_view);
		noNetData_tv1 = (TextView) view.findViewById(R.id.tv_no_net_tv1);
		noNetData_tv2 = (TextView) view.findViewById(R.id.tv_no_net_tv2);
		mRefreshButton = (Button) view.findViewById(R.id.freflush_net_btn);
		mRefreshNoDateButton = (Button) view.findViewById(R.id.freflush_nodate_btn);
		nodataView = (LinearLayout) view.findViewById(R.id.nodate_view);
		nodata_tv1 = (TextView) view.findViewById(R.id.nodata_tv1);
		nodata_tv2 = (TextView) view.findViewById(R.id.nodata_tv2);
		loadingView = (LinearLayout) view.findViewById(R.id.loadingview);
		mIvAnim = (ImageView) view.findViewById(R.id.iv_loading_anim);
		mAnim = (AnimationDrawable) mIvAnim.getBackground();
		// mAnim.setOneShot(false);
		// loadingView.setGravity(Gravity.CENTER);
		view.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
				LayoutParams.FILL_PARENT));
		relativeLayout_right = (RelativeLayout) view
				.findViewById(R.id.baby_title_view_relativelayout_right);
		relativeLayout_left = (RelativeLayout) view
				.findViewById(R.id.baby_title_view_relativelayout_left);
		addView(view);
		button_right.setVisibility(View.INVISIBLE);
	}

	/**
	 * 获取标题栏下部的布局
	 * 
	 * @return RelativeLayout
	 */
	public RelativeLayout getRelativeLayout() {
		return relativeLayout;
	}

	/**
	 * 获取标题TextView
	 * 
	 * @return TextView
	 */
	public TextView getTextView() {
		return textView;
	}

	/**
	 * 获取标题左边button
	 * 
	 * @return Button
	 */
	public Button getButton_left() {
		return button_left;
	}
	/**
	 * 获取标题左边relativelayout
	 * 
	 * @return Button
	 */
	public RelativeLayout getRelativelayout_left() {
		return reLayout_left;
	}

	/**
	 * 获取标题右边button
	 * 
	 * @return Button
	 */
	public Button getButton_right() {
		return button_right;
	}
	/**
	 * 获取标题右边边relativelayout
	 * 
	 * @return Button
	 */
	public RelativeLayout getRelativelayout_right() {
		return reLayout_right;
	}

	/**
	 * 获取 title 标题布局
	 * 
	 * @return FrameLayout
	 */
	public FrameLayout getFramelayout() {
		return framelayout;
	}

	/**
	 * 添加view
	 */
	public void addRelativeLayoutView(View child) {
		if (relativeLayout != null)
			relativeLayout.addView(child);
	}

	/**
	 * 获取标题栏中间位置的view
	 * 
	 * @return
	 * @author wangbingqi
	 */
	public LinearLayout getLinearlayout() {
		return linearlayout;
	}

	public RelativeLayout getRelativeLayoutForRight() {
		return relativeLayout_right;
	}

	public RelativeLayout getRelativeLayoutForLeft() {
		return relativeLayout_left;
	}

	/**
	 * 获取蒙层 view
	 * 
	 * @return
	 */
	public RelativeLayout getRelativeLayoutMengCeng() {
		return mRLMengCeng;
	}
}

